package net.youyi.crazycopyer.ui;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import net.youyi.crazycopyer.R;
import net.youyi.crazycopyer.fragment.DiscussFragment;
import net.youyi.crazycopyer.fragment.VideoDetailFragment;

/**
 * Created by xzp on 15/11/9.
 */
public class BiliDetailActivity extends BaseActivity{
    private ImageView mDetailImage;
    private ViewPager mViewPager;
    private TabLayout mTabLayout;
    private MyPagerAdapter mAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bili_detail);
        mDetailImage= (ImageView) this.findViewById(R.id.detail_image);
        Glide.with(this).load("http://i2.hdslb.com/video/6a/6a609daf7a250c6bad07efc766f464c5.jpg")
                .centerCrop()
                .into(mDetailImage);
        mViewPager= (ViewPager) this.findViewById(R.id.view_pager);
        mAdapter=new MyPagerAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(mAdapter);
        mTabLayout= (TabLayout) this.findViewById(R.id.tab_layout);
        mTabLayout.setupWithViewPager(mViewPager);
    }
    private class MyPagerAdapter extends FragmentPagerAdapter{
        private String[] titles={"视频详情","相关视频","评论(250)"};

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            if(position!=2)
                return new VideoDetailFragment();
            else
                return new DiscussFragment();
        }

        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }
    }
}
